#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k,t;
int _a[100020];
int a[100020];
int ans[100020];
int X[4];
struct Query
{
	int c;
	int id;
	bool operator < (const Query a) const
	{
		return c<a.c;
	}
};
Query c[100020];
char d[20][140020];
int sum[20][140020];
int win[20][140020];
inline int calc(int l,int r){return (l+r)*(r-l+1)/2;}
void build(int k,int x)
{
	win[k][x]=-1;
	if(k)
	{
		build(k-1,x<<1);
		build(k-1,x<<1|1);
		sum[k][x]=sum[k-1][x<<1]+sum[k-1][x<<1|1];
	}
	else sum[k][x]=x+1;
	//~ printf("build(%lld,%lld) win=%lld sum=%lld\n",k,x,win[k][x],sum[k][x]);
}
void insert(int x,int v)
{
	//~ printf("insert(%lld,%lld)\n",x,v);
	sum[0][x]=x+1;win[0][x]=x;
	for(int i=1;i<=k;i++)
	{
		//~ printf("x=%lld i=%lld sum[x]=%lld sum[x^1]=%lld\n",x,i,sum[i-1][x],sum[i-1][x^1]);
		if(x&1)// right
		{
			if(d[i][x>>1]=='0')
			{
				//~ assert(win[i-1][x^1]>=0);
				if(a[win[i-1][x^1]]>=i)
				{
					//~ printf("1\n");
					win[i][x>>1]=win[i-1][x^1],sum[i][x>>1]=sum[i-1][x^1];
				}
				else
				{
					//~ printf("2\n");
					win[i][x>>1]=win[i-1][x],sum[i][x>>1]=sum[i-1][x];
				}
			}
			else
			{
				if(win[i-1][x]>=0 && a[win[i-1][x]]<i)
				{
					//~ printf("3\n");
					win[i][x>>1]=win[i-1][x^1],sum[i][x>>1]=sum[i-1][x^1];
				}
				else if(win[i-1][x]>=0 && a[win[i-1][x]]>=i)
				{
					//~ printf("4\n");
					win[i][x>>1]=win[i-1][x],sum[i][x>>1]=sum[i-1][x];
				}
				else
				{
					//~ printf("5\n");
					win[i][x>>1]=-1,sum[i][x>>1]=sum[i-1][x^1]+sum[i-1][x];
				}
			}
		}
		else// left
		{
			if(d[i][x>>1]=='0')
			{
				if(win[i-1][x]>=0 && a[win[i-1][x]]<i)
				{
					//~ printf("6\n");
					win[i][x>>1]=win[i-1][x^1],sum[i][x>>1]=sum[i-1][x^1];
				}
				else if(win[i-1][x]>=0 && a[win[i-1][x]]>=i)
				{
					//~ printf("7\n");
					win[i][x>>1]=win[i-1][x],sum[i][x>>1]=sum[i-1][x];
				}
				else
				{
					//~ printf("8\n");
					win[i][x>>1]=-1,sum[i][x>>1]=sum[i-1][x^1]+sum[i-1][x];
				}
			}
			else
			{
				//~ printf("i=%lld k=%lld : ok\n",i,k);
				//~ printf("9\n");
				win[i][x>>1]=-1;
				sum[i][x>>1]=sum[i-1][x^1]+sum[i-1][x];
			}
		}
		x>>=1;
		if(!x) break;
		//~ printf("win[%lld][%lld]=%lld sum[%lld][%lld]=%lld\n",i,x,win[i][x],i,x,sum[i][x]);
	}
}
void solve()
{
	cin>>X[0]>>X[1]>>X[2]>>X[3];
	for(int i=1;i<=n;i++) a[i-1]=_a[i-1]^X[i%4];
	build(k,0);
	for(int i=0,j=1;i<n;i++)
	{
		insert(i,a[i]);
		//~ printf("finished\n");
		while(j<=m && c[j].c==i)
		{
			//~ printf("j=%lld\n",j);
			if(i) ans[c[j].id]=sum[__lg(i)+1][0];
			else ans[c[j].id]=1;
			j++;
		}
	}
	//~ for(int i=1;i<=m;i++) printf("%lld ",ans[i]);printf("\n");
	int ret=0;
	for(int i=1;i<=m;i++) ret^=i*ans[i];
	printf("%lld\n",ret);
}
signed main()
{
	freopen("arena.in","r",stdin);
	freopen("arena.out","w",stdout);
	cin>>n>>m;
	for(int i=0;i<n;i++) scanf("%lld",&_a[i]);
	for(int i=1;i<=m;i++)
	{
		scanf("%lld",&c[i].c);
		c[i].id=i;
		c[i].c--;
	}
	sort(c+1,c+m+1);
	while((1<<k)<n) k++;
	for(int i=1;i<=k;i++)
	{
		scanf("%s",d[i]);
	}
	cin>>t;
	while(t--) solve();
	return 0;
}
